<template>
  <div class="td-doctor">
    <router-view></router-view>
    <mt-tabbar class="td-patient-tabbar" fixed v-model="selected" v-if="isTabbar">
      <mt-tab-item id="检测" @click.native="$router.push({name:'tdDoctorHome'});">
        <img slot="icon" src="../../assets/images/doctor/tabbar-shouye.png">
        首页
      </mt-tab-item>
      <mt-tab-item id="论坛" @click.native="$router.push({name:'tdDoctorForum'});">
        <img slot="icon" src="../../assets/images/doctor/tabbar-luntan.png">
        论坛
      </mt-tab-item>
      <mt-tab-item id="我的" @click.native="$router.push({name:'tdDoctorMe'});">
        <img slot="icon" src="../../assets/images/doctor/tabbar-wode.png">
        我的
      </mt-tab-item>
    </mt-tabbar>
  </div>
</template>

<script>
import DoctorService from "../../_services/doctor.service";
import HospitalService from "../../_services/hospital.service";
export default {
  name: "TianDingDoctorComponent",
  data() {
    return {
      user: {},
      selected: "我的",
      isTabbar: true
    };
  },
  mounted() {
    this.user = JSON.parse(this.local$.getItem("tdUser"));
    this.getUserInfo();
  },
  methods: {
    toPath(name) {
      if (this.user.AuditStatus === 0 || this.user.AuditStatus === 1) {
      } else {
        this.$router.push({ name: name });
      }
    },
    getUserInfo() {
      let params = {};
      params.doctorID = this.user.DoctorID;
      DoctorService.getDoctorByID(params).then(doctorResponse => {
        HospitalService.getHospitalListByDoctor(params).then(
          hospitalResponse => {
            doctorResponse.Data.hospitalList = hospitalResponse.Data;
            this.local$.removeItem("tdUser");
            this.local$.setItem("tdUser", JSON.stringify(doctorResponse.Data));
          }
        );
      });
    }
  },
  watch: {
    $route(now, old) {
      if (
        now.name !== "tdDoctorMe" &&
        now.name !== "tdDoctorForum" &&
        now.name !== "tdDoctorHome"
      ) {
        this.isTabbar = false;
      } else {
        this.isTabbar = true;
      }
    }
  }
};
</script>
